﻿@model Category
@{
    ViewBag.Title = "Edit";
    List<Category> categoryList = ViewBag.ParentId ?? new List<Category>();
}
<style>
    html {
        background: #fff;
    }
</style>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    @Html.AntiForgeryToken()

    <input type="hidden" name="Id" value="@(Model?.Id??0)" />


    <div class="layui-form-item">
        @Html.LabelFor(model => model.CategoryName, new { @class = "layui-form-label", @for = "CategoryName" })
        <div class="layui-input-block">
            @Html.TextBoxFor(model => model.CategoryName, new { lay_verify = "required", autocomplete = "off", @class = "layui-input" })
        </div>
    </div>

    <div class="layui-form-item">
        @Html.LabelFor(model => model.ParentId, new { @class = "layui-form-label", @for = "ParentId" })
        <div class="layui-input-block">
            <select class="layui-input" name="ParentId" id="ParentId">
                <option value="" @Html.Raw(null != Model && Model.ParentId == null ? "selected=\"selected\"" : "")>无父级</option>
                @foreach (var item in categoryList)
                {
                <option value="@item.Id" @Html.Raw(null != Model && Model.ParentId == item.Id ? "selected=\"selected\"" : "")>@Html.Raw(CommonService.GetWhiteSpace(item.ParentIdList.Count))@item.CategoryName</option>
                }
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        @Html.LabelFor(model => model.OrderId, new { @class = "layui-form-label", @for = "OrderId" })
        <div class="layui-input-block">
            @Html.TextBoxFor(model => model.OrderId, new { lay_verify = "required", autocomplete = "off", @class = "layui-input" })
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
</div>

@section scripts
{
    <script>
        layui.config({
            base: '/Content/LayuiAdmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
            , laydate = layui.laydate;

																																	laydate.render({
                elem: '#CreateTime',
                type: 'datetime'
            });
									            //监听提交
            form.on('submit(layuiadmin-app-form-edit)', function (data) {
                var field = data.field; //获取提交的字段
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

                //提交 Ajax 成功后，关闭当前弹层并重载表格
                admin.req({
                    url: '@(Url.Action("Edit"))'
                    , type: "POST"
                    , data: field
                    , done: function (res) {
                        if (res.statusCode === 0) {
                            parent.layui.table.reload('LAY-app-content-list'); //重载表格
                            parent.layer.close(index); //再执行关闭
                            parent.parent.layer.msg(res.message, { offset: '15px', icon: 1 });
                        } else {
                            parent.parent.layer.msg(res.message, { offset: '15px', icon: 5 });
                        }
                    },
                    error: function (res) {
                        console.log('error='+res);
                    }
                });
            });
        })
    </script>
}

